package com.vetalitet.components;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.View;
import android.widget.RelativeLayout;

import static com.vetalitet.components.MathUtils.findPointOnCircleByDegree;

public class TestDrawable extends RelativeLayout {

    private final static int COMPONENT_RECT_SIZE = 200;
    private final static int DEGREE = 5;

    private Path path;
    private Paint paint;

    private int centerX;
    private int centerY;
    private int radius;

    private TopArcView topArc;
    private BottomArcView bottomArc;

    public TestDrawable(Context context) {
        super(context);
        init(context);
    }

    public TestDrawable(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
        //initMenuButtons();
    }

    private void init(Context context) {
        path = new Path();
        paint = new Paint();
        centerX = COMPONENT_RECT_SIZE / 2;
        centerY = COMPONENT_RECT_SIZE / 2;
        radius = COMPONENT_RECT_SIZE / 2;
        setWillNotDraw(false);
        topArc = new TopArcView(context);
        bottomArc = new BottomArcView(context);
        addView(topArc);
        addView(bottomArc);
        initAnimation(context);
    }

    private void initAnimation(Context context) {
        final
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(COMPONENT_RECT_SIZE, COMPONENT_RECT_SIZE);
    }

    class TopArcView extends View {

        TopArcView(Context context) {
            super(context);
        }

        TopArcView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            paint.reset();
            path.reset();
            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.STROKE);
            paint.setColor(Color.parseColor("#000000"));
            final RectF pos = new RectF(centerX - 100, centerY - 100, centerX + 100, centerY + 100);
            path.arcTo(pos, 180 + DEGREE, 180 - DEGREE * 2);
            final Pair<Float, Float> finishPoint = findPointOnCircleByDegree(centerX, centerY, radius, DEGREE);
            path.moveTo(finishPoint.first, finishPoint.second);
            path.close();
            canvas.drawPath(path, paint);
        }

    }

    class BottomArcView extends View {

        BottomArcView(Context context) {
            super(context);
        }

        BottomArcView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            paint.reset();
            path.reset();
            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.STROKE);
            paint.setColor(Color.parseColor("#000000"));
            final RectF pos = new RectF(centerX - 100, centerY - 100, centerX + 100, centerY + 100);
            path.arcTo(pos, DEGREE, 180 - DEGREE * 2);
            final Pair<Float, Float> finishPoint = findPointOnCircleByDegree(centerX, centerY, radius, 360 - DEGREE);
            path.moveTo(finishPoint.first, finishPoint.second);
            path.close();
            canvas.drawPath(path, paint);
        }

    }

}
